﻿#include "zuhechaxun.h"
#include "ui_zuhechaxun.h"
#include <QDebug>
Form2::Form2(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Form2)
{
    ui->setupUi(this);
    //ui.scrollAreaWidgetContents->adjustSize();
    //connect(ui->treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), ui->treeWidget_2, SLOT(slotDoubleClickItem(QTreeWidgetItem *, int)));
    connect(ui->treeWidget_2,SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),this,SLOT(showSelectedImage(QTreeWidgetItem*,int)));
    //时间设置
    ui->renzhis->setDisplayFormat("yyyy-MM-dd");//设置输出格式 ; 开始时间格式为2000-01-01 样式
    ui->renzhis->setCalendarPopup(true);
    ui->renzhie->setDisplayFormat("yyyy-MM-dd");//设置输出格式 ; 开始时间格式为2000-01-01 样式
    ui->renzhie->setCalendarPopup(true);
    ui->births->setDisplayFormat("yyyy-MM-dd");//设置输出格式 ; 开始时间格式为2000-01-01 样式
    ui->births->setCalendarPopup(true);
    ui->birthe->setDisplayFormat("yyyy-MM-dd");//设置输出格式 ; 开始时间格式为2000-01-01 样式
    ui->birthe->setCalendarPopup(true);
    ui->daiyus->setDisplayFormat("yyyy-MM-dd");//设置输出格式 ; 开始时间格式为2000-01-01 样式
    ui->daiyus->setCalendarPopup(true);
    ui->daiyue->setDisplayFormat("yyyy-MM-dd");//设置输出格式 ; 开始时间格式为2000-01-01 样式
    ui->daiyue->setCalendarPopup(true);
    ui->rudangs->setDisplayFormat("yyyy-MM-dd");//设置输出格式 ; 开始时间格式为2000-01-01 样式
    ui->rudangs->setCalendarPopup(true);
    ui->rudange->setDisplayFormat("yyyy-MM-dd");//设置输出格式 ; 开始时间格式为2000-01-01 样式
    ui->rudange->setCalendarPopup(true);
    ui->joinworks->setDisplayFormat("yyyy-MM-dd");//设置输出格式 ; 开始时间格式为2000-01-01 样式
    ui->joinworks->setCalendarPopup(true);
    ui->joinworke->setDisplayFormat("yyyy-MM-dd");//设置输出格式 ; 开始时间格式为2000-01-01 样式
    ui->joinworke->setCalendarPopup(true);







}
Form2::~Form2()
{
    delete ui;
}

//void Form2::slotDoubleClickItem(QTreeWidgetItem *item, int col)
//{
// 从item中获得QString text()或者QVariant data()
// QTreeWidgetItem *parent=item->parent();//获得父节点
// if(NULL==parent)
//     return;
//progessBar->setValue(0);//进度条置0
//int row=parent->indexOfChild(item);//获得节点在父节点中的行号(从0开始)
//QString text=parent->text(0);//获得父节点的文本字符(即影像路径)
//qDebug()<<text;
//qDebug()<<row;
/* QString->const char* */
// QByteArray ba=fileName.toLocal8Bit();
//const char* filePath=ba.data();
//QVariant data();
// QString text();

//}

//void Form2::on_treeWidget_doubleClicked(const QModelIndex &index)
//{

// QModelIndex index1=ui->treeWidget->itemFromIndex(index);
//qDebug()<<"row"<<index.topLevelItem();
//qDebug()<<"cloumn"<<index.column();
// 从item中获得QString text()或者QVariant data()
// QTreeWidgetItem *parent=item->parent();//获得父节点
// if(NULL==parent)
//     return;
//progessBar->setValue(0);//进度条置0
// int row=parent->indexOfChild(item);//获得节点在父节点中的行号(从0开始)
// QString text=parent->text(0);//获得父节点的文本字符(即影像路径)
//qDebug()<<text;
// qDebug()<<row;


//    const bool __sortingEnabled = treeWidget->isSortingEnabled();
//    treeWidget->setSortingEnabled(false);
//   QTreeWidgetItem *___qtreewidgetitem = treeWidget->topLevelItem(0);

// QTreeWidgetItem *___qtreewidgetitem1 = ___qtreewidgetitem->child(0);

//QTreeWidgetItem *___qtreewidgetitem2 = ___qtreewidgetitem->child(1);

//QTreeWidgetItem *___qtreewidgetitem3 = treeWidget->topLevelItem(1);

//    QTreeWidgetItem *___qtreewidgetitem4 = ___qtreewidgetitem3->child(0);

//    QTreeWidgetItem *___qtreewidgetitem5 = ___qtreewidgetitem3->child(1);

//    QTreeWidgetItem *___qtreewidgetitem6 = ___qtreewidgetitem3->child(2);

// QTreeWidgetItem *___qtreewidgetitem7 = treeWidget->topLevelItem(2);

//    QTreeWidgetItem *___qtreewidgetitem8 = ___qtreewidgetitem7->child(0);

//    QTreeWidgetItem *___qtreewidgetitem9 = ___qtreewidgetitem7->child(1);

//    treeWidget->setSortingEnabled(__sortingEnabled);


//}


void Form2::showSelectedImage(QTreeWidgetItem *item, int column)
{
    QTreeWidgetItem * currentItem = ui->treeWidget_2->currentItem();
    QTreeWidgetItem *parent = item->parent();
    //QTreeWidgetItem *parent = currentItem->parent();
    if(NULL==parent) //注意：最顶端项是没有父节点的，双击这些项时注意(陷阱)
        return;
    int col =parent->indexOfChild(item); //item在父项中的节点行号(从0开始)

    if(0==col) //Band1
    {
        qDebug()<<"1";
        qDebug()<<column;
        //delete ui->treeWidget_2->takeTopLevelItem(ui->treeWidget_2->currentIndex().row());//删除全部节点
        //delete ui->treeWidget_2->currentItem->parent()->takeChild(ui->treeWidget_2->currentIndex().row());
        delete currentItem->parent()->takeChild(ui->treeWidget_2->currentIndex().row());//删除当前节点
    }
    if(1==col) //Band2
    {
        qDebug()<<"2";
        qDebug()<<column;
        //delete ui->treeWidget_2->currentItem->parent->takeChild(ui->treeWidget_2->currentIndex().row());
        delete currentItem->parent()->takeChild(ui->treeWidget_2->currentIndex().row());//删除当前节点
    }
}

void Form2::on_pushButton_clicked()//重名干部
{
    same=new samename();
    same->show();

}
